package hms.database;

import hms.master.MasterController;

public class DAOnoGUI {
	static int openConnections = 0;
	static DAO accessObject;

	public static DAO getDAO() {
		DAO localDAO = MasterController.getDatabaseObject();
		if(localDAO==null) {
			if(openConnections==0){
				accessObject = new DAO("HMSDatabase","db_files\\", true); // points to directory HMSProject/db_files/HMSDatabase.*
				accessObject.open();  // if class can recognize database, no exceptions printed to screen
			}
			localDAO = accessObject;
			openConnections++;
		}
		return localDAO;
	}
	
	public static void closeDAO() {
		if(MasterController.getDatabaseObject()==null) {
			--openConnections;
			if(openConnections == 0) {
				accessObject.close();
			}
		}
	}
}
